<?php
/**
 * Override or insert vars into the page template.
 */
function solveto_process_page(&$vars) {
    // Hook into color.module.
    if (module_exists('color')) {
        _color_page_alter($vars);
    }

    $status = drupal_get_http_header("status");
    if($status == "404 Not Found") {
        $vars['theme_hook_suggestions'][] = 'page__404';
    }

    $vars['social_links'] = 0;

    // Always print the site name and slogan, but if they are toggled off, we'll
    // just hide them visually.
    $vars['hide_site_name']   = theme_get_setting('toggle_name') ? FALSE : TRUE;
    $vars['hide_site_slogan'] = theme_get_setting('toggle_slogan') ? FALSE : TRUE;
    if ($vars['hide_site_name']) {
        // If toggle_name is FALSE, the site_name will be empty, so we rebuild it.
        $vars['site_name'] = filter_xss_admin(variable_get('site_name', 'Drupal'));
    }
    if ($vars['hide_site_slogan']) {
        // If toggle_site_slogan is FALSE, the site_slogan will be empty, so we rebuild it.
        $vars['site_slogan'] = filter_xss_admin(variable_get('site_slogan', ''));
    }
    // Since the title and the shortcut link are both block level elements,
    // positioning them next to each other is much simpler with a wrapper div.
    if (!empty($vars['title_suffix']['add_or_remove_shortcut']) && $vars['title']) {
        // Add a wrapper div using the title_prefix and title_suffix render elements.
        $vars['title_prefix']['shortcut_wrapper'] = array(
            '#markup' => '<div class="shortcut-wrapper clearfix">',
            '#weight' => 100,
        );
        $vars['title_suffix']['shortcut_wrapper'] = array(
            '#markup' => '</div>',
            '#weight' => -99,
        );
        // Make sure the shortcut link is the first item in title_suffix.
        $vars['title_suffix']['add_or_remove_shortcut']['#weight'] = -100;
    }

}

/**
 * Implements hook_preprocess_page().
 */
function solveto_preprocess_page(&$vars, $hook) {
    global $base_url;
    $themepath = drupal_get_path('theme','solveto');
    // LOGO SETTINGS
    $variables['logo'] = $base_url.'/'.$themepath.'/logo.png';
    if(theme_get_setting('default_logo') == 0) {
        if(module_exists('media')) {
            if($file_upload = theme_get_setting('logo_normal_media_file')) {
                if(!empty($file_upload)) {
                    $file = json_decode($file_upload);
                    if($file) {
                        $variables['logo'] = $file->url;
                    }
                }
            }
        } else {
            if ($logo_file = theme_get_setting('logo_normal_form_file')) {
                $variables['logo'] =  file_create_url(file_build_uri($logo_file));
            }
        }
    }

    // Page title in node page

    if(isset($vars['node'])) {
        $node = $vars['node'];
        $vars['page_title'] = $vars['node']->type;
        // Check and create previous and next link of current node
        $nid = $node->nid;
        $node_type = $node->type;
        $query = db_select('node', 'n');
        $query->fields('n', array('nid'))
            ->condition('type', $node_type)
            ->orderBy('nid');
        $result = $query->execute();
        $nids = array();
        while ($record = $result->fetchAssoc()) {
            $nids[] .= $record['nid'];
        }
        $current_node_key =  array_search($nid, $nids);
        if(($current_node_key-1) > 0) {
            $vars['previous_link'] = url('node/'.$nids[$current_node_key-1],array('absolute'=>true));
        }
        if(($current_node_key + 1) != sizeof($nids)) {
            $vars['next_link'] = url('node/'.$nids[$current_node_key+1],array('absolute'=>true));
        }

    }
    if(theme_get_setting('footer_text')){
        $vars['footer_text'] = theme_get_setting('footer_text');
    }
    if(strpos(current_path(),'portfolio_popup') !== false) {

    }
    $themepath = drupal_get_path('theme','solveto');

}
/**
 * Implements hook_preprocess_maintenance_page().
 */
function solveto_preprocess_maintenance_page(&$vars) {
    $theme_path = drupal_get_path('theme','solveto');

    if (!$vars['db_is_active']) {
        unset($vars['site_name']);
    }
    // Always print the site name and slogan, but if they are toggled off, we'll
    // just hide them visually.
    $vars['hide_site_name']   = theme_get_setting('toggle_name') ? FALSE : TRUE;
    $vars['hide_site_slogan'] = theme_get_setting('toggle_slogan') ? FALSE : TRUE;
    if ($vars['hide_site_name']) {
        // If toggle_name is FALSE, the site_name will be empty, so we rebuild it.
        $vars['site_name'] = filter_xss_admin(variable_get('site_name', 'Drupal'));
    }
    if ($vars['hide_site_slogan']) {
        // If toggle_site_slogan is FALSE, the site_slogan will be empty, so we rebuild it.
        $vars['site_slogan'] = filter_xss_admin(variable_get('site_slogan', ''));
    }
}
